package com.ys.service.wallet;

import com.ys.service.wallet.base.IWalletService;
import com.ys.service.wallet.btc.BtcWalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Component
@Slf4j
public class WalletJobServiceContent implements InitializingBean, ApplicationContextAware {

    private ApplicationContext context;
    private Map<String, IWalletJobService> IWalletJobServiceMap =new ConcurrentHashMap<>();

    /**
     * 获取钱包service
     * @param code
     * @return
     */
    public IWalletJobService getWalletJobService(Integer code) {

        for (Map.Entry<String, IWalletJobService> entry : IWalletJobServiceMap.entrySet()) {

            if(code.intValue()==entry.getValue().getCurrency().intValue()){
                return entry.getValue();
            }


        }
        log.error("不支持的资产类型："+code);
        return null;
    }



    @Override
    public void afterPropertiesSet() throws Exception {
        IWalletJobServiceMap = context.getBeansOfType(IWalletJobService.class);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
}
